home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / snk68.c < prev    next >
C/C++ Source or Header  |  2000-04-11  |  9KB  |  378 lines

  1. /***************************************************************************
  2.  
  3.     SNK 68000 video routines
  4.  
  5. Notes:
  6.     Search & Rescue uses Y flip on sprites only.
  7.     Street Smart uses X flip on sprites only.
  8.  
  9.     Seems to be controlled in same byte as flipscreen.
  10.  
  11.     Emulation by Bryan McPhail, mish@tendril.co.uk
  12.  
  13. ***************************************************************************/
  14.  
  15. #include "driver.h"
  16. #include "vidhrdw/generic.h"
  17.  
  18. static int sprite_flip,flipscreen;
  19. static struct tilemap *fix_tilemap;
  20.  
  21. /***************************************************************************
  22.  
  23.   Callbacks for the TileMap code
  24.  
  25. ***************************************************************************/
  26.  
  27. static void get_pow_tile_info(int tile_index)
  28. {
  29.     int tile=READ_WORD(&videoram[4*tile_index])&0xff;
  30.     int color=READ_WORD(&videoram[4*tile_index+2]);
  31.  
  32.     tile=((color&0xf0)<<4) | tile;
  33.     color&=0xf;
  34.  
  35.     SET_TILE_INFO(0,tile,color)
  36. }
  37.  
  38. static void get_sar_tile_info(int tile_index)
  39. {
  40.     int tile=READ_WORD(&videoram[4*tile_index]);
  41.     int color=tile >> 12;
  42.  
  43.     tile=tile&0xfff;
  44.  
  45.     SET_TILE_INFO(0,tile,color)
  46. }
  47.  
  48. static void get_ikari3_tile_info(int tile_index)
  49. {
  50.     int tile=READ_WORD(&videoram[4*tile_index]);
  51.     int color=tile >> 12;
  52.  
  53.     /* Kludge - Tile 0x80ff is meant to be opaque black, but isn't.  This fixes it */
  54.     if (tile==0x80ff) {
  55.         tile=0x2ca;
  56.         color=7;
  57.     } else
  58.         tile=tile&0xfff;
  59.  
  60.     SET_TILE_INFO(0,tile,color)
  61. }
  62.  
  63. /***************************************************************************
  64.  
  65.   Start the video hardware emulation.
  66.  
  67. ***************************************************************************/
  68.  
  69. int pow_vh_start(void)
  70. {
  71.     fix_tilemap = tilemap_create(get_pow_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,8,8,32,32);
  72.  
  73.     if (!fix_tilemap)
  74.         return 1;
  75.  
  76.     fix_tilemap->transparent_pen = 0;
  77.  
  78.     return 0;
  79. }
  80.  
  81. int searchar_vh_start(void)
  82. {
  83.     fix_tilemap = tilemap_create(get_sar_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,8,8,32,32);
  84.  
  85.     if (!fix_tilemap)
  86.         return 1;
  87.  
  88.     fix_tilemap->transparent_pen = 0;
  89.  
  90.     return 0;
  91. }
  92.  
  93. int ikari3_vh_start(void)
  94. {
  95.     fix_tilemap = tilemap_create(get_ikari3_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,8,8,32,32);
  96.  
  97.     if (!fix_tilemap)
  98.         return 1;
  99.  
  100.     fix_tilemap->transparent_pen = 0;
  101.  
  102.     return 0;
  103. }
  104.  
  105. /***************************************************************************
  106.  
  107.   Memory handlers
  108.  
  109. ***************************************************************************/
  110.  
  111. WRITE_HANDLER( pow_flipscreen_w )
  112. {
  113.     flipscreen=data&0x8;
  114.     sprite_flip=data&0x4;
  115. }
  116.  
  117. WRITE_HANDLER( pow_paletteram_w )
  118. {
  119.     int oldword = READ_WORD (&paletteram[offset]);
  120.     int newword = COMBINE_WORD (oldword, data);
  121.     int r,g,b;
  122.  
  123.     WRITE_WORD (&paletteram[offset], newword);
  124.  
  125.     r = ((newword >> 7) & 0x1e) | ((newword >> 14) & 0x01);
  126.     g = ((newword >> 3) & 0x1e) | ((newword >> 13) & 0x01) ;
  127.     b = ((newword << 1) & 0x1e) | ((newword >> 12) & 0x01) ;
  128.  
  129.     r = (r << 3) | (r >> 2);
  130.     g = (g << 3) | (g >> 2);
  131.     b = (b << 3) | (b >> 2);
  132.  
  133.     palette_change_color(offset / 2,r,g,b);
  134. }
  135.  
  136. WRITE_HANDLER( pow_video_w )
  137. {
  138.     if ((data>>16)==0xff)
  139.         WRITE_WORD(&videoram[offset],(data>>8)&0xff);
  140.     else
  141.         WRITE_WORD(&videoram[offset],data);
  142.  
  143.     tilemap_mark_tile_dirty(fix_tilemap,offset/4);
  144. }
  145.  
  146.  
  147. /***************************************************************************
  148.  
  149.   Display refresh
  150.  
  151. ***************************************************************************/
  152.  
  153. static void draw_sprites(struct osd_bitmap *bitmap, int j,int pos)
  154. {
  155.     int offs,mx,my,color,tile,fx,fy,i;
  156.  
  157.     for (offs = pos; offs < pos+0x800; offs += 0x80 )
  158.     {
  159.         mx=(READ_WORD(&spriteram[offs+4+(4*j)])&0xff)<<4;
  160.         my=READ_WORD(&spriteram[offs+6+(4*j)]);
  161.         mx=mx+(my>>12);
  162.         mx=((mx+16)&0x1ff)-16;
  163.  
  164.         mx=((mx+0x100)&0x1ff)-0x100;
  165.         my=((my+0x100)&0x1ff)-0x100;
  166.  
  167.         my=0x200 - my;
  168.         my-=0x200;
  169.  
  170.         if (flipscreen) {
  171.             mx=240-mx;
  172.             my=240-my;
  173.         }
  174.  
  175.         for (i=0; i<0x80; i+=4) {
  176.             color=READ_WORD(&spriteram[offs+i+(0x1000*j)+0x1000])&0x7f;
  177.  
  178.             if (color) {
  179.                 tile=READ_WORD(&spriteram[offs+2+i+(0x1000*j)+0x1000]);
  180.                 fy=tile&0x8000;
  181.                 fx=tile&0x4000;
  182.                 tile&=0x3fff;
  183.  
  184.                 if (flipscreen) {
  185.                     if (fx) fx=0; else fx=1;
  186.                     if (fy) fy=0; else fy=1;
  187.                 }
  188.  
  189.                 drawgfx(bitmap,Machine->gfx[1],
  190.                     tile,
  191.                     color,
  192.                     fx,fy,
  193.                     mx,my,
  194.                     0,TRANSPARENCY_PEN,0);
  195.             }
  196.  
  197.             if (flipscreen) {
  198.                 my-=16;
  199.                 if (my < -0x100) my+=0x200;
  200.             }
  201.             else {
  202.                 my+=16;
  203.                 if (my > 0x100) my-=0x200;
  204.             }
  205.         }
  206.     }
  207. }
  208.  
  209.  
  210. void pow_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
  211. {
  212.     int offs,color,i;
  213.     int colmask[0x80],code,pal_base;
  214.  
  215.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  216.  
  217.     /* Update fix chars */
  218.     tilemap_update(fix_tilemap);
  219.  
  220.     /* Build the dynamic palette */
  221.     palette_init_used_colors();
  222.  
  223.     /* Tiles */
  224.     pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
  225.     for (color = 0;color < 128;color++) colmask[color] = 0;
  226.     for (offs = 0x1000;offs <0x4000;offs += 4 )
  227.     {
  228.         code = READ_WORD(&spriteram[offs+2])&0x3fff;
  229.         color= READ_WORD(&spriteram[offs])&0x7f;
  230.         colmask[color] |= Machine->gfx[1]->pen_usage[code];
  231.     }
  232.     for (color = 1;color < 128;color++)
  233.     {
  234.         for (i = 1;i < 16;i++)
  235.         {
  236.             if (colmask[color] & (1 << i))
  237.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  238.         }
  239.     }
  240.  
  241.     palette_transparent_color=2047;
  242.     palette_used_colors[2047] = PALETTE_COLOR_USED;
  243.     if (palette_recalc())
  244.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  245.     fillbitmap(bitmap,palette_transparent_pen,&Machine->drv->visible_area);
  246.  
  247.     tilemap_render(ALL_TILEMAPS);
  248.  
  249.     /* This appears to be correct priority */
  250.     draw_sprites(bitmap,1,0x000);
  251.     draw_sprites(bitmap,1,0x800);
  252.     draw_sprites(bitmap,0,0x000);
  253.     draw_sprites(bitmap,2,0x000);
  254.     draw_sprites(bitmap,2,0x800);
  255.     draw_sprites(bitmap,0,0x800);
  256.  
  257.     tilemap_draw(bitmap,fix_tilemap,0);
  258. }
  259.  
  260.  
  261. static void draw_sprites2(struct osd_bitmap *bitmap, int j, int z, int pos)
  262. {
  263.     int offs,mx,my,color,tile,fx,fy,i;
  264.  
  265.     for (offs = pos; offs < pos+0x800 ; offs += 0x80 )
  266.     {
  267.         mx=READ_WORD(&spriteram[offs+j]);
  268.         my=READ_WORD(&spriteram[offs+j+2]);
  269.  
  270.         mx=mx<<4;
  271.         mx=mx|((my>>12)&0xf);
  272.         my=my&0x1ff;
  273.  
  274.         mx=(mx+0x100)&0x1ff;
  275.         my=(my+0x100)&0x1ff;
  276.         mx-=0x100;
  277.         my-=0x100;
  278.         my=0x200 - my;
  279.         my-=0x200;
  280.  
  281.         if (flipscreen) {
  282.             mx=240-mx;
  283.             my=240-my;
  284.         }
  285.  
  286.         for (i=0; i<0x80; i+=4) {
  287.             color=READ_WORD(&spriteram[offs+i+z])&0x7f;
  288.             if (color) {
  289.                 tile=READ_WORD(&spriteram[offs+2+i+z]);
  290.                 if (sprite_flip) {
  291.                     fx=0;
  292.                     fy=tile&0x8000;
  293.                 } else {
  294.                     fy=0;
  295.                     fx=tile&0x8000;
  296.                 }
  297.  
  298.                 if (flipscreen) {
  299.                     if (fx) fx=0; else fx=1;
  300.                     if (fy) fy=0; else fy=1;
  301.                 }
  302.  
  303.                 tile&=0x7fff;
  304.                 if (tile>0x5fff) break;
  305.  
  306.                 drawgfx(bitmap,Machine->gfx[1],
  307.                     tile,
  308.                     color,
  309.                     fx,fy,
  310.                     mx,my,
  311.                     0,TRANSPARENCY_PEN,0);
  312.             }
  313.             if (flipscreen) {
  314.                 my-=16;
  315.                 if (my < -0x100) my+=0x200;
  316.             }
  317.             else {
  318.                 my+=16;
  319.                 if (my > 0x100) my-=0x200;
  320.             }
  321.         }
  322.     }
  323. }
  324.  
  325.  
  326. void searchar_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
  327. {
  328.     int offs,color,i;
  329.     int colmask[0x80],code,pal_base;
  330.  
  331.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  332.  
  333.     /* Update fix chars */
  334.     tilemap_update(fix_tilemap);
  335.  
  336.     /* Build the dynamic palette */
  337.     palette_init_used_colors();
  338.  
  339.     /* Tiles */
  340.     pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
  341.     for (color = 0;color < 128;color++) colmask[color] = 0;
  342.     for (offs = 0x1000;offs <0x4000;offs += 4 )
  343.     {
  344.         code = READ_WORD(&spriteram[offs+2])&0x7fff;
  345.         color= READ_WORD(&spriteram[offs])&0x7f;
  346.         if (code>0x5fff) code=0;
  347.         if (color)
  348.             colmask[color] |= Machine->gfx[1]->pen_usage[code];
  349.     }
  350.     /* Palette 0 is "don't display" */
  351.     for (color = 1;color < 128;color++)
  352.     {
  353.         for (i = 1;i < 16;i++)
  354.         {
  355.             if (colmask[color] & (1 << i))
  356.                 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
  357.         }
  358.     }
  359.  
  360.     palette_transparent_color=2047;
  361.     palette_used_colors[2047] = PALETTE_COLOR_USED;
  362.     if (palette_recalc())
  363.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  364.     fillbitmap(bitmap,palette_transparent_pen,&Machine->drv->visible_area);
  365.  
  366.     tilemap_render(ALL_TILEMAPS);
  367.  
  368.     /* This appears to be correct priority */
  369.     draw_sprites2(bitmap,8,0x2000,0x000);
  370.     draw_sprites2(bitmap,8,0x2000,0x800);
  371.     draw_sprites2(bitmap,12,0x3000,0x000);
  372.     draw_sprites2(bitmap,12,0x3000,0x800);
  373.     draw_sprites2(bitmap,4,0x1000,0x000);
  374.     draw_sprites2(bitmap,4,0x1000,0x800);
  375.  
  376.     tilemap_draw(bitmap,fix_tilemap,0);
  377. }
  378.